{
    "cells": [
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": [
                "import numpy as np\n",
                "import matplotlib.pyplot as plt\n",
                "%matplotlib inline\n"
            ]
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "## Part (e)\n"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": [
                "sample_size = [5, 25, 125, 625]\n",
                "plt.figure(figsize=[12, 10])\n",
                "\n",
                "for k in range(4):\n",
                "\n",
                "    # generate data\n",
                "    # np.linspace, np.random.normal and np.random.uniform might be useful functions\n",
                "    ### start 1 ###\n",
                "\n",
                "    ### end 1 ###\n",
                "\n",
                "    likelihood = np.ones(N) # likelihood as a function of w\n",
                "    for i1 in range(N):\n",
                "        # compute likelihood\n",
                "        ### start 2 ###\n",
                "\n",
                "        ### end 2 ###\n",
                "\n",
                "    likelihood /= sum(likelihood)\n",
                "    plt.subplot(2, 2, k + 1)\n",
                "    plt.plot(W, likelihood)\n",
                "    plt.xlabel('w', fontsize=10)\n",
                "    plt.legend(['n=' + str(n)], fontsize=14)\n",
                "# plt.savefig('uni_noise_post.pdf') # command to save figure\n",
                "plt.show()\n"
            ]
        },
        {
            "cell_type": "markdown",
            "metadata": {},
            "source": [
                "## Part (h)\n"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "metadata": {},
            "outputs": [],
            "source": [
                "plt.figure(figsize=[15, 5])\n",
                "sample_size = [5, 25, 125]\n",
                "# W = (W1, W2) is drawn from (has prior of) a zero-mean Gaussian distribution with\n",
                "# standard deviation, sigma. Let's assume that true W = (0.4, 0.5) and sigma is 0.5.\n",
                "w1, w2 = 0.4, 0.5\n",
                "sigma = 0.5\n",
                "\n",
                "for k in range(3):\n",
                "    n = sample_size[k]\n",
                "    N = 201\n",
                "    W = np.linspace(-5, 5, N)\n",
                "\n",
                "    # generate data\n",
                "    # np.linspace, np.random.normal and np.random.uniform might be useful functions\n",
                "    ### start 3 ###\n",
                "\n",
                "    ### end 3 ###\n",
                "\n",
                "    # compute likelihood\n",
                "    likelihood = np.ones([N, N]) # likelihood as a function of w1 and w0\n",
                "\n",
                "    for i1 in range(N):\n",
                "        w1s = W[i1]\n",
                "        for i2 in range(N):\n",
                "            w2s = W[i2]\n",
                "            # compute the likelihood here\n",
                "            ### start 4 ###\n",
                "\n",
                "            ### end 4 ###\n",
                "\n",
                "    # plotting the likelihood\n",
                "    plt.subplot(1, 3, k + 1)\n",
                "    plt.imshow(np.flipud(likelihood), cmap='hot', aspect='auto', extent=[-5, 5, -5, 5])\n",
                "    plt.xlabel('w1')\n",
                "    plt.ylabel('w2')\n",
                "    plt.title('n=%d' % n)\n",
                "plt.show()\n"
            ]
        }
    ],
    "metadata": {
        "kernelspec": {
            "display_name": "Python 3",
            "language": "python",
            "name": "python3"
        },
        "language_info": {
            "codemirror_mode": {
                "name": "ipython",
                "version": 3
            },
            "file_extension": ".py",
            "mimetype": "text/x-python",
            "name": "python",
            "nbconvert_exporter": "python",
            "pygments_lexer": "ipython3",
            "version": "3.8.3"
        }
    },
    "nbformat": 4,
    "nbformat_minor": 4
}